package org.jacp.demo.util;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Set;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.jacp.demo.main.ImageDemoLauncher;

public class ScrollDemo extends JFrame {

	  JScrollPane scrollpane;

	  public ScrollDemo() {
	    super("JScrollPane Demonstration");
	    setSize(300, 200);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    init();
	    setVisible(true);
	  }

	  public void init() {
		  List<String> colorKeys = new ArrayList<String>();
		  try {
			    try {
					UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} catch (final InstantiationException ex) {
			    Logger.getLogger(ImageDemoLauncher.class.getName()).log(
				    Level.SEVERE, null, ex);
			} catch (final IllegalAccessException ex) {
			    Logger.getLogger(ImageDemoLauncher.class.getName()).log(
				    Level.SEVERE, null, ex);
			} catch (final UnsupportedLookAndFeelException ex) {
			    Logger.getLogger(ImageDemoLauncher.class.getName()).log(
				    Level.SEVERE, null, ex);
			}
		    Set<Entry<Object, Object>> entries = UIManager.getLookAndFeelDefaults().entrySet();
		    for (Entry entry : entries)
		    {
		      if (entry.getValue() instanceof Color)
		      {
		        colorKeys.add((String) entry.getKey());
		      }
		    }

		    // sort the color keys
		    Collections.sort(colorKeys);
	    JPanel p = new JPanel();
	    p.setSize(600, 400);
	    p.setLayout(new GridLayout(13, 6, 10, 0));
	    for (int row = 0; row < colorKeys.size(); row++) {
	    	String color = colorKeys.get(row);
	     JLabel label = new JLabel(color); 
	     p.setBackground(Color.black);
	     Color c = UIManager.getColor(color);
	     label.setForeground(c);
	     p.add(label);
	     System.out.println(color+"  : "+c.getRed()+" : "+c.getGreen()+" : "+c.getBlue());
	    }
	    scrollpane = new JScrollPane(p);
	    getContentPane().add(scrollpane, BorderLayout.CENTER);
	  }

	  public static void main(String args[]) {
	    new ScrollDemo();
	  }
	}

